<?php 
class controller_contentObject{
	
	public function pageAdminContent($param){
		$classTree = Import::loadClass('tree','library/');
		$param['directory'] = $classTree->directory;
		
		$classContentObject = Import::loadClass('contentobject','library/contentobject/');		
		$dataStruct = $classContentObject->getStructureAndStructureElem();
		$param['dataStruct'] = $dataStruct;
		
		if(isset($param['arbo'][3]) && !empty($param['arbo'][3])){
			$contentobject_id = $param['arbo'][3];
			$classContentObject = Import::loadClass('contentobject','library/contentobject/');
			$dataContent = $classContentObject->getContentAndElem(array('contentobject_id'=>$contentobject_id));
	
//			echo'<pre>';
//				print_r($dataContent);
//			echo'</pre>';

			$param['dataContent'] = $dataContent;
		}
		
		return 'library/contentobject/views/pageContenu.tpl.php';
	}
	
	public function pageAdminContentEdit($param){
		$classTree = Import::loadClass('tree','library/');
		$param['directory'] = $classTree->directory;

		$classContentObject = Import::loadClass('contentobject','library/contentobject/');		
		$content_id = $param['arbo'][4];
		
		$dataContent = $classContentObject->getContentAndElem(array('contentobject_id'=>$content_id));
		$dataContent = $dataContent[0];
		
//		echo'<pre>';
//		print_r($dataContent);
//		echo'</pre>';
	
		$structure_id = $dataContent['contentobject_structure_id'];
		
		$dataStruct = $classContentObject->getStructureAndStructureElem(array('contentobject_structure_id'=>$structure_id));
		$param['dataStruct'] = $dataStruct;
		$param['dataContent'] = $dataContent;

		return 'library/contentobject/views/pageContenu-edit.tpl.php';
	}
	public function pageAdminContentEdit_post($param){
		$classTree = Import::loadClass('tree','library/');
		$param['directory'] = $classTree->directory;

		$classContentObject = Import::loadClass('contentobject','library/contentobject/');		
		$content_id = $param['arbo'][4];
		
		$dataContent = $classContentObject->getContentAndElem(array('contentobject_id'=>$content_id));
		$dataContent = $dataContent[0];
		
		echo'<pre>';
		print_r($dataContent);
		echo'</pre>';
	
		$structure_id = $dataContent['contentobject_structure_id'];
		
		$dataStruct = $classContentObject->getStructureAndStructureElem(array('contentobject_structure_id'=>$structure_id));
		$param['dataStruct'] = $dataStruct;
		$param['dataContent'] = $dataContent;

		return 'library/contentobject/views/pageContenu-edit.tpl.php';
	}
	
	public function pageAdminContentAdd($param){
		$classTree = Import::loadClass('tree','library/');
		$param['directory'] = $classTree->directory;

		$structure_id = $param['arbo'][4];	
		
		$classContentObject = Import::loadClass('contentobject','library/contentobject/');
		$dataStruct = $classContentObject->getStructureAndStructureElem(array('contentobject_structure_id'=>$structure_id));
		$param['dataStruct'] = $dataStruct;

		return 'library/contentobject/views/pageContenu-add.tpl.php';
	}
	public function pageAdminContentAdd_post($param){
//		echo'<pre>';
//		print_r($_POST);
//		echo'</pre>';
		
		$classTree = Import::loadClass('tree','library/');
		$param['directory'] = $classTree->directory;

		//add structure
		$structure_id = $param['arbo'][4];	
		$_POST['contentobject']['contentobject_structure_id'] =$structure_id;
		
		$classContentObject = Import::loadClass('contentobject','library/contentobject/');
		$classContentObject->createContent($_POST);
		$dataStruct = $classContentObject->getStructureAndStructureElem(array('contentobject_structure_id'=>$structure_id));
		$param['dataStruct'] = $dataStruct;

		return 'library/contentobject/views/pageContenu-add.tpl.php';
	}
	
	
	public function pageAdminStruture($param){
		$classContentObject = Import::loadClass('contentobject','library/contentobject/');
		$dataStruct = $classContentObject->getStructureAndStructureElem();
		$param['dataStruct'] = $dataStruct;
		
		return 'library/contentobject/views/pageStruture.tpl.php';
	}
	
	public function pageAdminStrutureAdd($param){
		return 'library/contentobject/views/pageStruture-add.tpl.php';
	}
	public function pageAdminStrutureAdd_post($param){
		$data = $_POST;
		$classStructure = Import::loadClass('contentobject','library/contentobject/');
		$classStructure->createStructure($data);
		
		return $this->pageAdminStrutureAdd($param);
	}

	public function pageAdminStrutureEdit($param){
		$structure_id = $param['arbo'][4];		
		$classStructure = Import::loadClass('contentobject','library/contentobject/');
		$param['dataStruct'] = $classStructure->getStructureAndStructureElem(array('contentobject_structure_id'=>$structure_id));
		
		return 'library/contentobject/views/pageStruture-edit.tpl.php';
	}
	
	public function pageAdminStrutureEdit_post($param){
//		echo'<pre>';
//		print_r($_POST);
//		echo'</pre>';
		
		$structure_id = $param['arbo'][4];		
		$classStructure = Import::loadClass('contentobject','library/contentobject/');
		$classStructure->editStructure($_POST);
		
		$param['dataStruct'] = $classStructure->getStructureAndStructureElem(array('contentobject_structure_id'=>$structure_id));
		
		return 'library/contentobject/views/pageStruture-edit.tpl.php';
	}
	
	public function pageAdminCategory($param){
		return 'library/contentobject/views/pageCategory.tpl.php';
	}
	
	public function pageAdminCategoryAdd($param){
	//		echo"<pre>";
	//		print_r($this);
	//		echo"</pre>";

		return 'library/contentobject/views/pageCategory-add.tpl.php';
	}
}
?>